package com.gopay.common.domain.acps;

import com.gopay.common.cipher.utils.SensitiveInfoUtils;
import org.apache.commons.lang.StringUtils;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

/**
 * CLASSNAME:AcctBalanceWarning
 * Description:余额预警信息配置表
 * DATE:2017/12/18/018
 * @author:PANSHICHAO
 * www.gopay.com.cn Inc.All rights reserved.
 */
@Entity
@Table(name = "ACCT_BALANCE_WARNING")
public class AcctBalanceWarning implements Serializable,Cloneable {
    private static final long serialVersionUID = 1;
    private String infoID;
    private String custID;
    private String acctID;
    private String balanceWarningOpen;
    private String balanceWarningType;
    private String balanceWarningEmail;
    private String balanceWarningPhone;
    private BigDecimal balanceNotifyQuota;
    private BigDecimal balanceWarningQuota;
    private Date createTs;
    private Date lastUpdTs;
    private Integer version;
    private static final String SPLIT_TARGET=",";
    @Id
    @GenericGenerator(name="systemUUID",strategy="uuid")
    @GeneratedValue(generator="systemUUID")
    @Column(name = "INFO_ID", unique = true, nullable = false, length = 40)
    public String getInfoID() {
        return infoID;
    }
    @Column(name = "CUST_ID", unique = true, nullable = false, length = 10)
    public String getCustID() {
        return custID;
    }
    @Column(name = "ACCT_ID", unique = true, nullable = false, length = 19)
    public String getAcctID() {
        return acctID;
    }
    @Column(name = "IS_BALANCE_WARNING_OPEN", unique = true, nullable = false, length = 4)
    public String getBalanceWarningOpen() {
        return balanceWarningOpen;
    }
    @Column(name = "BALANCE_WARNING_QUOTA", unique = true, nullable = false)
    public BigDecimal getBalanceWarningQuota() {
        return balanceWarningQuota;
    }
    @Column(name = "BALANCE_WARNING_TYPE",length = 4)
    public String getBalanceWarningType() {
        return balanceWarningType;
    }
    @Column(name = "BALANCE_WARNING_EMAIL",length = 50)
    public String getBalanceWarningEmail() {
        return balanceWarningEmail;
    }
    @Column(name = "BALANCE_WARNING_PHONE")
    public String getBalanceWarningPhone() {
        if(StringUtils.isBlank(balanceWarningPhone)){
            return "";
        }
        else if(balanceWarningPhone.indexOf(SPLIT_TARGET) == -1)
        {
            String phone = SensitiveInfoUtils.smartDecryptWithCheck(balanceWarningPhone);
            return phone;
        }
        else
        {
            String [] phones = balanceWarningPhone.split(SPLIT_TARGET);
            String firstPhone = SensitiveInfoUtils.smartDecryptWithCheck(phones[0]);
            String endPhone = SensitiveInfoUtils.smartDecryptWithCheck(phones[1]);
            balanceWarningPhone = firstPhone+SPLIT_TARGET+ endPhone;
            return balanceWarningPhone;
        }
    }
    @Column(name = "CREATED_TS")
    @Temporal(TemporalType.TIMESTAMP)
    public Date getCreateTs() {
        return (Date) createTs.clone();
    }
    @Column(name = "LAST_UPD_TS")
    @Temporal(TemporalType.TIMESTAMP)
    public Date getLastUpdTs() {
        return (Date) lastUpdTs.clone();
    }
    @Version
    @Column(name = "VERSION", nullable = false, precision = 22, scale = 0)
    public Integer getVersion() {
        return version;
    }

    public void setInfoID(String infoID) {
        this.infoID = infoID;
    }

    public void setCustID(String custID) {
        this.custID = custID;
    }

    public void setAcctID(String acctID) {
        this.acctID = acctID;
    }

    public void setBalanceWarningOpen(String balanceWarningOpen) {
        this.balanceWarningOpen = balanceWarningOpen;
    }

    public void setBalanceWarningQuota(BigDecimal balanceWarningQuota) {
        this.balanceWarningQuota = balanceWarningQuota;
    }

    public void setBalanceWarningType(String balanceWarningType) {
        this.balanceWarningType = balanceWarningType;
    }

    public void setBalanceWarningEmail(String balanceWarningEmail) {
        this.balanceWarningEmail = balanceWarningEmail;
    }

    public void setBalanceWarningPhone(String balanceWarningPhone) {
        if(StringUtils.isBlank(balanceWarningPhone)){
            this.balanceWarningPhone = "";
        }
        else if(balanceWarningPhone.indexOf(SPLIT_TARGET) != -1)
        {
            String [] phones = balanceWarningPhone.split(SPLIT_TARGET);
            this.balanceWarningPhone = SensitiveInfoUtils.smartEncryptWithCheck(phones[0])+","+SensitiveInfoUtils.smartEncryptWithCheck(phones[1]);
        }
        else
        {
            this.balanceWarningPhone = SensitiveInfoUtils.smartEncryptWithCheck(balanceWarningPhone);
        }
    }
    public void setCreateTs(Date createTs) {
        this.createTs = (Date) createTs.clone();
    }

    public void setLastUpdTs(Date lastUpdTs) {
        this.lastUpdTs = (Date) lastUpdTs.clone();
    }

    public void setVersion(Integer version) {
        this.version = version;
    }
    @Column(name = "BALANCE_NOTIFY_QUOTA")
    public BigDecimal getBalanceNotifyQuota() {
        return balanceNotifyQuota;
    }

    public void setBalanceNotifyQuota(BigDecimal balanceNotifyQuota) {
        this.balanceNotifyQuota = balanceNotifyQuota;
    }

    public AcctBalanceWarning() {

    }

    public AcctBalanceWarning(String infoID, String custID, String acctID, String balanceWarningOpen, String balanceWarningType, String balanceWarningEmail, String balanceWarningPhone, BigDecimal balanceNotifyQuota, BigDecimal balanceWarningQuota,Integer version) {
        this.infoID = infoID;
        this.custID = custID;
        this.acctID = acctID;
        this.balanceWarningOpen = balanceWarningOpen;
        this.balanceWarningType = balanceWarningType;
        this.balanceWarningEmail = balanceWarningEmail;
        this.balanceWarningPhone = balanceWarningPhone;
        this.balanceNotifyQuota = balanceNotifyQuota;
        this.balanceWarningQuota = balanceWarningQuota;
        this.createTs = new Date();
        this.lastUpdTs = new Date();
        this.version = version;
    }
}
